package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.result.R;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "医院接口")//swagger注解
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin 配置gateway网关后,不需要该注解 网关已经解决跨域问题
public class HospitalController {
    @Autowired
    HospitalService hospitalService;

    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public R index(@PathVariable Integer page, @PathVariable Integer limit, HospitalQueryVo hospitalQueryVo) {
        //调用方法
        return R.ok().data("pages",hospitalService.selectPage(page, limit, hospitalQueryVo));
    }

    @ApiOperation(value = "更新status(上线)状态,1为已上线,0为已下线")
    @GetMapping("updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable String id,
                          @PathVariable Integer status){
        hospitalService.updateStatus(id,status);
        return R.ok();
    }
    @ApiOperation(value = "显示医院详情信息")
    @GetMapping("show/{id}")
    public R show(@PathVariable String id){
        Hospital hospital = hospitalService.show(id);
        return   R.ok().data("hospital",hospital);

    }

}
